package com.zhang.test_zhang.service.impl;

import com.zhang.test_zhang.entity.User;
import com.zhang.test_zhang.mapper.UserMapper;
import com.zhang.test_zhang.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.UUID;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;
    /**
     * 新增用户
     * @param user
     * @return
     */
    @Override
    public String newUser(User user) {
        int id = UUID.randomUUID().toString().replaceAll("-", "").hashCode();
        id = id < 0 ? -id : id;

        user.setId(id);
        userMapper.newUser(user);

        return "新增成功！";
    }

    /**
     * 查询用户金额
     * @param id
     * @return
     */
    @Override
    public User getWallet(int id) {

        User wallet = userMapper.getWallet(id);

        return wallet;
    }
}
